﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.Finances;
@using DCMS.ViewModel.Models.Sales;
@using System.Collections.Generic;
@using System.Linq;
@using DCMS.Core.Domain.Common;

@model SaleReportSummaryBusinessDailyListModel

<section id="content_wrapper">
    <div id="topbar-dropmenu">
        @await Html.PartialAsync("_ToolBox")
    </div>
    <header id="topbar">
        <div class="topbar-left">
            <ol class="breadcrumb">
                <li class="crumb-active">
                    <a href="#">销售</a>
                </li>
                <li class="crumb-icon">
                    <a href="@Url.RouteUrl("HomePage")">
                        <span class="glyphicon glyphicon-home"></span>
                    </a>
                </li>
                <li class="crumb-link">
                    <a href="#">销售报表</a>
                </li>
                <li class="crumb-trail">经营日报表</li>
            </ol>
        </div>
        <div class="topbar-right">
            <div class="ml15 ib va-m" id="toggle_sidemenu_r">
                <a href="#" class="pl5">
                    <i class="fa fa-sign-in fs22 text-primary"></i>
                    <span class="badge badge-hero badge-danger">3</span>
                </a>
            </div>
        </div>
    </header>
    <section id="content" class="formSection">
        <div class="special-alerts">
            <div class="alert alert-danger light alert-dismissable" id="alert-demo-2" style="display: none;">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <i class="fa fa-info pr10"></i>
                <strong>您没有被授权此操作!</strong>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <form asp-action="SaleReportSummaryBusinessDaily" asp-controller="SaleReport" method="get" id="fromSearch" novalidate="novalidate">
                    <div class="panel panel-default" id="panel0">
                        <div class="panel-heading">
                            <span class="glyphicon glyphicon-search"></span> 高级搜索
                            <a class="btn btn-default btn-sm pull-right m5 mrn p5 pbn" id="AdvancedSearch"><i class="fa fa-angle-double-right"></i></a>
                        </div>
                        <div class="panel-body p10">

                            <div class="row">
                                <div class="col-sm-2">
                                    <dcms-editor asp-for="StartTime" placeholder="开始..." />
                                </div>
                                <div class="col-sm-2">
                                    <dcms-editor asp-for="EndTime" placeholder="结束..." />
                                </div>
                                <div class="col-sm-2">
                                    <dcms-select asp-for="BusinessUserId" asp-items="@Model.BusinessUsers" asp-default="业务员" />
                                </div>
                                <div class="col-sm-6">
                                    <button id="btn_query" type="submit" class="btn btn-primary btn-block">
                                        <span class="glyphicon glyphicon-search mr5" aria-hidden="true"></span>查询
                                    </button>
                                </div>

                            </div>
                        </div>
                    </div>
                </form>
                <div class="panel">
                    <div class="panel-heading">
                        <div class="panel-title">
                            <span class="glyphicon glyphicon-tasks"></span> 报表
                        </div>
                    </div>
                    <div class="panel-body p10">
                        <div class="bootstrap-table">
                            <div id="toolbar" class="btn-group mb10 mt10">
                                <a href="@Url.Action("SaleReportItem")" class="btn btn-default btn-sm">
                                    <span class="glyphicon glyphicon-refresh mr5"></span>重置
                                </a>
                            </div>
                            <div class="fixed-table-container">
                                <div class="fixed-table-body" id="tableDiv" style="overflow-x:auto;">
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr class="datagrid-header-row">
                                                <th class="text-center"><div class="th-inner">时间</div></th>
                                                <th class="text-left"><div class="th-inner">业务员</div></th>
                                                <th class="text-left"><div class="th-inner">销售数量</div></th>
                                                <th class="text-left"><div class="th-inner">销售金额</div></th>
                                                <th class="text-left"><div class="th-inner">赠送数量</div></th>
                                                <th class="text-left"><div class="th-inner">赠送成本</div></th>
                                                <th class="text-left"><div class="th-inner">退货数量</div></th>
                                                <th class="text-left"><div class="th-inner">退货金额</div></th>
                                                <th class="text-left"><div class="th-inner">优惠</div></th>
                                                <th class="text-left"><div class="th-inner">收款金额</div></th>
                                                <th class="text-left"><div class="th-inner">欠款金额</div></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @{
                                                if (Model.Items != null && Model.Items.Count > 0)
                                                {
                                                    foreach (var item in Model.Items)
                                                    {
                                                        <tr>
                                                            <td class="text-left">@item.DateName</td>
                                                            <td class="text-left">@item.BusinessName</td>
                                                            <td class="text-left">@item.SaleQuantity</td>
                                                            <td class="text-left">@item.SaleAmount.ToString("0.00")</td>
                                                            <td class="text-left">@item.GiftQuantity</td>
                                                            <td class="text-left">@item.GiftCostAmount.ToString("0.00")</td>
                                                            <td class="text-left">@item.ReturnQuantity</td>
                                                            <td class="text-left">@item.ReturnAmount.ToString("0.00")</td>
                                                            <td class="text-left">@item.PreferentialAmount.ToString("0.00")</td>
                                                            <td class="text-left">@item.ProceedsAmount.ToString("0.00")</td>
                                                            <td class="text-left">@item.BalanceAmount.ToString("0.00")</td>
                                                        </tr>
                                                    }
                                                    <tr>
                                                        <td class="text-left"></td>
                                                        <td class="text-left">合计</td>
                                                        <td class="text-left"><b>@Model.Items.Sum(s => s.SaleQuantity)</b></td>
                                                        <td class="text-left"><span style="color:#ffd700;"><b>￥</b></span><b>@Model.Items.Sum(s => s.SaleAmount).ToString("0.00")</b></td>
                                                        <td class="text-left"><b>@Model.Items.Sum(s => s.GiftQuantity)</b></td>
                                                        <td class="text-left"><span style="color:#ffd700;"><b>￥</b></span><b>@Model.Items.Sum(s => s.GiftCostAmount).ToString("0.00")</b></td>
                                                        <td class="text-left"><b>@Model.Items.Sum(s => s.ReturnQuantity)</b></td>
                                                        <td class="text-left"><span style="color:#ffd700;"><b>￥</b></span><b>@Model.Items.Sum(s => s.ReturnAmount).ToString("0.00")</b></td>
                                                        <td class="text-left"><span style="color:#ffd700;"><b>￥</b></span><b>@Model.Items.Sum(s => s.PreferentialAmount).ToString("0.00")</b></td>
                                                        <td class="text-left"><span style="color:#ffd700;"><b>￥</b></span><b>@Model.Items.Sum(s => s.ProceedsAmount).ToString("0.00")</b></td>
                                                        <td class="text-left"><span style="color:#ffd700;"><b>￥</b></span><b>@Model.Items.Sum(s => s.BalanceAmount).ToString("0.00")</b></td>
                                                    </tr>
                                                }
                                                else
                                                {
                                                    <tr class="no-records-found"><td class="text-center" colspan="11">没有找到匹配的记录</td></tr>
                                                }
                                            }
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            @{
                                var pager = Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber");
                            }

                            @if (!pager.IsEmpty())
                            {
                                <div class="fixed-table-pagination" style="display: block;">
                                    @Html.Raw(pager.ToString())
                                </div>
                            }
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</section>
